package com.net.xpay.common.domain;

import com.net.common.domain.CommonDomain;
import com.net.xpay.common.enums.user.CheckCodeType;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;

/**
 * 记录每一条短信验证码记录
 */
@Getter
@Setter
@NoArgsConstructor
public class CheckCodeLog extends CommonDomain {
    @ApiModelProperty(notes = "check_code.id")
    private Long checkCodeId;

    @ApiModelProperty(notes = "手机号")
    private String mobile;

    @ApiModelProperty(notes = "验证码类型")
    private CheckCodeType type;

    @ApiModelProperty(notes = "关联id")
    private Long relatedId;

    @ApiModelProperty(notes = "验证码")
    private String code;

    @ApiModelProperty(notes = "过期时间")
    private LocalDateTime expiredTime;

    @ApiModelProperty(notes = "发送时间")
    private LocalDateTime sendTime;

    @ApiModelProperty(notes = "出错的次数")
    private Long errorCnt;

    @ApiModelProperty(notes = "是否被验证通过了")
    private Boolean valid;

    @ApiModelProperty(notes = "系统ip")
    private String ip;

    public static CheckCodeLog getInstance(Long checkCodeId, String mobile, CheckCodeType type) {
        CheckCodeLog checkCode = new CheckCodeLog();
        checkCode.setMobile(mobile);
        checkCode.setCheckCodeId(checkCodeId);
        checkCode.setType(type);
        checkCode.setSendTime(LocalDateTime.now());
        checkCode.setErrorCnt(0L);
        checkCode.setValid(false);
        return checkCode;
    }
}
